import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-help' }
    }]
  },
  {
    path: '/auth',
    component: Layout,
    redirect: '/auth/user',
    name: 'Auth',
    meta: { title: '权限管理', icon: 'el-icon-user' },
    alwaysShow: true,
    children: [
      {
        path: 'user',
        name: 'AuthUser',
        component: () => import('@/views/auth/user/index'),
        meta: { title: '账号管理', icon: 'el-icon-user-solid' }
      },
      {
        path: 'role',
        name: 'AuthRole',
        component: () => import('@/views/auth/role/index'),
        meta: { title: '角色管理', icon: 'el-icon-s-custom' }
      },
      {
        path: 'permission',
        name: 'Permission',
        component: () => import('@/views/auth/permission/index'),
        meta: { title: '资源管理', icon: 'el-icon-s-promotion' }
      },
    ]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',
    name: 'Product',
    meta: { title: '商品管理', icon: 'el-icon-s-shop' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'ProductList',
        component: () => import('@/views/product/list/index'),
        meta: { title: '商品列表', icon: 'el-icon-goods' }
      },
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/views/product/category/index'),
        meta: { title: '商品分类', icon: 'el-icon-menu' }
      },
      {
        path: 'brand',
        name: 'ProductBrand',
        component: () => import('@/views/product/brand/index'),
        meta: { title: '品牌管理', icon: 'el-icon-present' }
      },
      {
        path: 'detail',
        name: 'ProductDetail',
        hidden:true,
        component: () => import('@/views/product/detail/index'),
        meta: { title: '商品编辑', icon: 'el-icon-present' }
      },
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    name: 'Order',
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'OrderList',
        component: () => import('@/views/order/list/index'),
        meta: { title: '订单列表', icon: 'el-icon-document-checked' }
      },
      {
        path: 'back',
        name: 'OrderBack',
        component: () => import('@/views/order/back/index'),
        meta: { title: '退单列表', icon: 'el-icon-document-delete' }
      },
      {
        path: 'address',
        name: 'OrderAddress',
        component: () => import('@/views/order/address/index'),
        meta: { title: '地址管理', icon: 'el-icon-school' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    name: 'User',
    meta: { title: '注册用户管理', icon: 'el-icon-s-custom' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'UserList',
        component: () => import('@/views/user/list/index'),
        meta: { title: '用户列表', icon: 'el-icon-user' }
      },
    ]
  },
  {
    path: '/market',
    component: Layout,
    redirect: '/market/list',
    name: 'Market',
    meta: { title: '营销管理', icon: 'el-icon-goods' },
    alwaysShow: true,
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/market/list/index'),
        meta: { title: '限时活动', icon: 'el-icon-files' }
      },
      {
        path: 'advertisement',
        name: 'Advertisement',
        component: () => import('@/views/market/advertisement/index'),
        meta: { title: '广告列表', icon: 'el-icon-document-copy' }
      },
    ]
  },
  {
    path: '/content',
    component: Layout,
    redirect: '/content/articleList',
    name: 'Content',
    meta: { title: '内容管理', icon: 'el-icon-folder' },
    alwaysShow: true,
    children: [
      {
        path: 'articleList',
        name: 'ArticleList',
        component: () => import('@/views/content/articleList/index'),
        meta: { title: '文章列表', icon: 'el-icon-document' }
      },
      {
        path: 'addArticle',
        name: 'AddArticle',
        hidden:true,
        component: () => import('@/views/content/articleList/addArticle'),
        meta: { title: '新增文章', icon: 'tree' }
      },
      {
        path: 'materialList',
        name: 'MaterialList',
        component: () => import('@/views/content/materialList/index'),
        meta: { title: '素材列表', icon: 'el-icon-picture-outline' }
      },
    ]
  },
  {
    path: '/person',
    component: Layout,
    redirect: '/person/index',
    name: 'Person',
    meta: { title: '个人中心', icon: 'el-icon-user-solid' },
    alwaysShow: true,
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/person/index/index'),
        meta: { title: '个人主页', icon: 'el-icon-user' }
      },
      {
        path: 'setting',
        name: 'Setting',
        component: () => import('@/views/person/setting/index'),
        meta: { title: '个人设置', icon: 'el-icon-setting' }
      },
    ]
  },
  // 出现404 产生的页面
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
